package jcl;

import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import static org.junit.Assert.assertTrue;

/**
 * Tests to see if MajorTom is constantly moving, thus being evasive.
 * 
 * @author Jerry Lau
 * 
 */
public class TestMajorTomEvasiveAction extends RobotTestBed {

  boolean evasiveAction = false;

  /**
   * Gets the name of the robots which will battle.
   * 
   * @return The list of robots in the match.
   */
  public String getRobotNames() {
    return "sample.SittingDuck,jcl.MajorTom";
  }

  /**
   * Runs for 10 rounds.
   * 
   * @return Number of rounds
   */
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks if the robot does NOT have a velocity of 0 (standing still).
   * 
   * @param event Battle info
   */
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];

    // Check to make sure the robot is not standing still
    if (robot.getVelocity() != 0) {
      evasiveAction = true;
    }
  }

  /**
   * After battle, check if robot velocity had been 0.
   * 
   * @param event Completed battle info
   */
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check if robot is always moving", evasiveAction);
  }

}
